package com.mijie.indexall;

import m.secury.callbackItfs;
import m.secury.securyWhile;

import org.apache.log4j.Logger;


import com.mijie.homi.common.domain.mood.Mood;
import com.mijie.homi.common.domain.topic.Topic;
import com.mijie.homi.search.util.god;
import com.mijie.query.fulltxtControllor4invoke;
import com.mijie.query.sincinController;


public class indexControllor4auto extends fulltxtControllor4invoke   {

	private static final String indexbatchID = "nbs";

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	//	indexControllor4auto.startAutoIndex();
		
		Mood m=new Mood();
		m.setId(490389);
		indexControllor4auto c=new indexControllor4auto();
		c.addindex(m);

	}

	public static Logger logger = Logger.getLogger(new indexControllor4auto()
			.getClass());

	static void startAutoIndex() {
		
		securyWhile securyWhile = new securyWhile(new callbackItfs() {
			
			@Override
			public Object callMethod(Object obj) {
				new indexControllor4auto().	whileItem();
				return null;
			}

			 
		}, logger, 2000, 3600*24*2, 90000);

//		while (true) {
//			try {
//				whileItem();
//
//			} catch (Exception e) {
//				logger.error(god.getTrace(e));
//			}
//
//			try {
//				Thread.sleep(3);
//			} catch (InterruptedException e) {
//				logger.error(god.getTrace(e));
//			}
//		}

	}

	private   void whileItem() {
		//indexControllor4auto c = new indexControllor4auto();
		sincinController sc = new sincinController();
		final Mood last = sc.getLast();
		if(last==null)
			logger.warn(" sincin last is null");
		final Topic last_prblm = sc.getLast_prblm();
		
		if(last_prblm==null)
			logger.warn(" last_prblm last is null");

		if (last != null)
			addindex(last);
//			god.newThread(new Runnable() {
//
//				@Override
//				public void run() {
//					addindex(last);
//
//				}
//
//				private void addindex(final Mood last) {
//					fulltxtControllor4invoke ici = new fulltxtControllor4invoke();
//					ici.indexBatchID=indexbatchID;
//					ici.writeToIndexSinglePerMessage(String.valueOf( last.getId()) ,
//							"sc");
//				}
//			}, "index_mood_thrd");

		if (last_prblm != null)
		{
			fulltxtControllor4invoke ici = new fulltxtControllor4invoke();
			ici.indexBatchID=indexbatchID;
			ici.writeToIndexSinglePerMessage( String.valueOf(last_prblm.getId())
					 , "pr");
		}
//			god.newThread(new Runnable() {
//
//				@Override
//				public void run() {
//					fulltxtControllor4invoke ici = new fulltxtControllor4invoke();
//					ici.indexBatchID=indexbatchID;
//					ici.writeToIndexSinglePerMessage( String.valueOf(last_prblm.getId())
//							 , "pr");
//
//				}
//			}, "index_prblm_thrd");
	}

	private void addindex(  Mood last) {
		fulltxtControllor4invoke ici = new fulltxtControllor4invoke();
		ici.indexBatchID=indexbatchID;
		ici.writeToIndexSinglePerMessage(String.valueOf( last.getId()) ,
				"sc");
	}

}
